<template>
  <view class="main">
    <view class="bg-set"></view>
    <view style="display: flex;width: 100%;justify-content: space-between;">
      <view style="margin-bottom: 20rpx;">意见建议:</view>
      <view class="time">{{ evaluationItem?.createTime }}</view>
    </view>
    <view class="evaStyle">{{ evaluationItem?.evaluationContent }}</view>
    <view class="line"></view>
    <!-- 商家回复区域需要判断 -->
    <view v-if="evaluationItem?.repContent" class="reply">
      <view style="display: flex;width: 100%;justify-content: space-between;">
        <view style="margin-bottom: 20rpx;">商家回复:</view>
        <view class="time">{{ evaluationItem?.repTime }}</view>
      </view>
      <view style="margin-bottom: 20rpx; word-break: break-all;">{{ evaluationItem?.repContent }}</view>
    </view>
    <view style="display: flex;justify-content: flex-end;margin-top: 10rpx;">
      <view class="btn_del" @click="onDel">删除</view>
    </view>
  </view>
</template>
<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { http } from '../../utils/http';
import { ref } from 'vue';
import { useMemberStore } from '../../stores';
const evaluationItem = ref()
const userStore = useMemberStore()
onLoad((e) => {
  evaluationItem.value = JSON.parse(e.evaluation)
  if (evaluationItem.value.repStatus == 3) {
    readEvaluationInfo()
  }

})
// 删除评价
const onDel = () => {
  uni.showModal({
    title: '确定删除该评价吗？',
    success: async (success) => {
      if (success.confirm) {
        const { errcode } = await http({
          method: 'post',
          url: '/DeleteEvaluationInfo',
          data: {
            ...userStore.requestData,
            data: {
              evaluationList: [
                {
                  evaluationSerials: evaluationItem.value.evaluationSerials
                }
              ]
            }
          }
        })

        if (errcode == 0) {
          uni.showToast({ title: '删除评价成功', icon: 'success', duration: 2000 })
          setTimeout(() => {

            uni.navigateBack()
          }, 500)
        }
      }
    },
  })
}
// 信息已读未读
const readEvaluationInfo = async () => {
  const res = await http({
    method: 'post',
    url: '/ReadEvaluationInfo',
    data: {
      ...userStore.requestData,
      data: {
        evaluationList: [
          {
            evaluationSerials: evaluationItem.value.evaluationSerials
          }
        ]
      }
    }
  })
  console.log(res, '已读');
}

</script>
<style scoped lang="scss">
.bg-set {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background-color: #f1f1f1;
  z-index: -1;
}

.btn_del {
  width: 150rpx;
  height: 100rpx;
  text-align: center;
  line-height: 100rpx;
  background-color: #95989d;
  border-radius: 12rpx;
}
.evaStyle{
  margin: 20rpx 0;
  width: 100%;
  word-break: break-all;
}
.main {
  width: 100%;
  padding: 30rpx;
  margin-top: 20rpx;
  background-color: #fff;
  box-sizing: border-box;

  .time {
    display: flex;
    justify-content: flex-end;
  }

  .line {
    width: 100%;
    height: 5rpx;
    margin-top: 10rpx;
    background-color: #eee;
  }

  .reply {
    margin-top: 10rpx;
  }
}
</style>